#ifndef SPRITE2D_H
#define SPRITE2D_H

#include <core/object.h>
#include <core/ref.h>
#include <graphics/rect.h>
//#include <graphics/mesh.h>
//#include <render/texture2d.h>

namespace yam3d
{
namespace render
{
    class Texture2D;
}

namespace graphics
{
    class Mesh;
    class Effect;

    class Sprite2D : public core::Object
    {
    public:

        Sprite2D(render::Texture2D* texture );
        virtual ~Sprite2D();

  //      void setTexture( render::Texture2D* texture );
        void setCrop(const Rect& crop);
        void setCrop(const math::vec2& start, const math::vec2& size);
        void setPixelCrop(const Rect& crop);
        void setPixelCrop(const math::vec2& start, const math::vec2& size);

        /**
         * Sets origin point of the sprite. <0,0> is at top left corner, <1,1> is at bottom right corner.
         * Initially sprite origin is at center <0.5, 0.5>.
         */
        void setPivot( const math::vec2& pivot )
        {
            m_pivot = (2.0f * pivot) - math::vec2(1.0f,1.0f);
            updateTransform();
        }

        void setTranslation( const math::vec2& translation )
        {
            m_translation = translation;
            updateTransform();
        }

        void setScale( const math::vec2& scale )
        {
            m_scale = scale;
            updateTransform();
        }

        void setRotation( float rotation )
        {
            m_rotation = rotation;
            updateTransform();
        }

        const graphics::Mesh* const getMesh() const;
        const graphics::Effect* const getEffect() const;
        const math::vec2& getCropStart() const;
        const math::vec2& getCropSize() const;
        math::vec2 getPixelCropStart() const;
        math::vec2 getPixelCropSize() const;

        const math::vec2& getPivot() const { return m_pivot; }
        const math::vec2& getTranslation() const { return m_translation; }
        const math::vec2& getScale() const { return m_scale; }
        float getRotation() const { return m_rotation; }
    private:
        core::Ref<Effect>   m_effect;
        Rect                m_crop;
        math::vec2          m_pivot;
        math::vec2          m_translation;
        math::vec2          m_scale;
        float               m_rotation;
        math::vec2          m_textureSize;

        void updateTransform();

        Sprite2D();
        Sprite2D(const Sprite2D&);
        Sprite2D& operator=(const Sprite2D&);
    };

}
}




#endif // SPRITE2D_H
